//
//  RWBlogCell.m
//  Chat
//
//  Created by 任伟 on 16/1/3.
//  Copyright © 2016年 任伟. All rights reserved.
//

#import "RWBlogCell.h"
#import "RWBlogModel.h"
#import "RWFrameModel.h"

@interface RWBlogCell()

/**
 *  头像
 */
@property (nonatomic, strong) UIImageView *headView;

/**
 *  名称
 */
@property (nonatomic, strong) UILabel *nameView;

/**
 *  vip
 */
@property (nonatomic, strong) UIImageView *vipView;

/**
 *  正文
 */
@property (nonatomic, strong) UILabel *textView;

/**
 *  配图
 */
@property (nonatomic, strong) UIImageView *pictureView;


@end

@implementation RWBlogCell

/**
 *  在这个方法中添加可能出现在cell中的所有子控件,把只是做一次的设置放在这个方法中,这样提升性能
 
 *
 */
- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {

    if (self= [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
    
        // 1. 头像控件
        UIImageView *headView = [[UIImageView alloc] init];
        [self.contentView addSubview:headView];
        self.headView = headView;
        
        // 2. 名称控件
        UILabel *nameView = [[UILabel alloc] init];
        [self.contentView addSubview:nameView];
        self.nameView = nameView;
        
        // 3. vip 图片
        UIImageView *vipView = [[UIImageView alloc] init];
        [self.contentView addSubview:vipView];
        self.vipView = vipView;
        self.vipView.image = [UIImage imageNamed:@"vip"];
        
        // 4. 正文
        UILabel *textView = [[UILabel alloc] init];
        [self.contentView addSubview:textView];
        textView.numberOfLines = 0;
        self.textView = textView;
        
        // 5. 配图
        UIImageView *pictureView = [[UIImageView alloc] init];
        [self.contentView addSubview:pictureView];
        self.pictureView = pictureView;
    }
    
    return self;
}

- (void)setBlogFrame:(RWFrameModel *)blogFrame {

    _blogFrame = blogFrame;
    
    // 1. 赋值数据
    [self settingData];
    
    // 2. 赋值frame
    [self settingFrame];
}

/**
 * 赋值数据
 */

- (void)settingData {

    // 1. 赋值头像
    self.headView.image = [UIImage imageNamed:self.blogFrame.blog.icon];
    
    // 2. 赋值名称
    self.nameView.text = self.blogFrame.blog.name;
    
    // 3. 赋值vip
    if (self.blogFrame.blog.vip) {
        
        self.vipView.hidden = NO;
        self.nameView.textColor = [UIColor redColor];
    
    } else {
        
        self.vipView.hidden = YES;
        self.nameView.textColor = [UIColor blackColor];
    }
    
    // 4. 赋值正文
    self.textView.text = self.blogFrame.blog.text;
    
    // 5. 赋值配图
    if (self.blogFrame.blog.picture) {
        
        self.pictureView.image = [UIImage imageNamed:self.blogFrame.blog.picture];
        self.pictureView.hidden = NO;
        
    } else {
    
        self.pictureView.hidden = YES;
    }
}

/**
 * 赋值frame
 */
- (void)settingFrame {
    
    // 1. 设值头像frame
    self.headView.frame = self.blogFrame.headF;
    
    // 2. 设值名称frame
    self.nameView.frame = self.blogFrame.nameF;
    
    // 3. 设值vipframe
    if (self.blogFrame.blog.vip) {
        
        self.vipView.frame = self.blogFrame.vipF;
        
    }
    
    // 4. 设值正文frame
    self.textView.frame = self.blogFrame.textViewF;
    
    // 5. 设值配图frame
    if (self.blogFrame.blog.picture) {
        
        self.pictureView.frame = self.blogFrame.pictureViewF;
    }
}

@end
